<?php

namespace app\api\controller;

use app\common\controller\Base as BaseController;

class User extends BaseController
{
    //用户登陆
    public function login()
    {
        $userLogic = \think\Loader::model('User', 'logic');

        /*
         * 根据type用不同的登陆方式
         * */
        switch (request()->param('type')) {
            case 'weixin':
                $info = $userLogic->login();
                break;
            case 'account':
                break;
            case 'email':
                break;
            default:
                break;

        }
        if (isset($info['userId'])) {
            //正确返回用户注册id
            $data = array(
                'token' => $this -> createToken($info['userId'])
            );
            $this->customizedResult(true, $data, '登录成功', '10000');
        } else {
            //微信用户注册失败
            $this->customizedResult(false, null, '登录失败', '10100');
        }
    }

    //获取注册用户信息
    public function getUserInfo()
    {
        $userLogic = \think\Loader::model('User', 'logic');
        $info = $userLogic->getUserInfo(request()->current_user->user_id);
        if (isset($info['nickName'])) {
            //正确返回用户信息
            $data = array(
                'nickName' => $info['nickName'],
                'userAvatar' => $info['userAvatar'],
                'realName' => $info['realName']
            );
            $this->customizedResult(true, $data, '获取用户信息成功', '10000');
        } else {
            //微信用户注册失败
            $this->customizedResult(false, null, '获取用户信息失败', '10100');
        }
    }
}
